<template>
	<view class="template-about">
		<!-- 顶部自定义导航 -->
		<tn-nav-bar fixed alpha customBack>
			<view slot="back" class='tn-custom-nav-bar__back' @click="goBack">
				<text class='icon tn-icon-left'></text>
				<text class='icon tn-icon-home-capsule-fill'></text>
			</view>
		</tn-nav-bar>

		<view :style="{marginTop: vuex_custom_bar_height + 'px'}">


			<view class="tn-margin-bottom-lg">
				<block v-for="(item, index) in reserve" :key="index">
					<view class="article-shadow tn-margin">
						<view class="tn-flex">
							<view class="image-pic tn-margin-sm" :style="'background-image:url(' + item.url + ')'">
								<view class="image-article">
								</view>
							</view>
							<view class="tn-margin-sm tn-padding-top-xs" style="width: 100%;">
								<view class="tn-text-lg tn-text-bold clamp-text-1 tn-text-justify">
									{{ item.title }}
								</view>

								<view class="tn-flex tn-flex-row-between tn-flex-col-between tn-padding-top-xs"
									style="min-height: 105rpx;">
									<text class="tn-text-df tn-color-gray clamp-text-2 tn-text-justify">
										{{ item.activityTime }}
										{{ item.location }}
									</text>
									<!-- <view class="justify-content-item tn-flex tn-flex-col-center">
					  <tn-avatar-group :lists="item.reserve.image" size="sm"></tn-avatar-group>
					</view> -->
									<view class="justify-content-item tn-flex tn-flex-col-center">
										<button class="info-btn" @click="showDetail(item.id)">参与详情</button>
									</view>

								</view>
								<view class="tn-flex tn-flex-row-between tn-flex-col-between">
									<view class="justify-content-item tn-text-center " style="padding-top: 5rpx;">

										<text class=" tn-padding-right-xs tn-text-lg">{{ item.joinNum }} 人参与</text>

									</view>
									<text class="tn-icon-delete tn-color-black tn-text-bold tn-text-xxl"
										@click="deleteActivity(item,index)"></text>
								</view>
							</view>
						</view>
					</view>
				</block>

				<block v-if="reserve.length == 0">
					<view style="text-align: center;font-size: 12px;padding-top: 130px;">
						<view>
							<img src="../../../static/img/logo2.png"
								style="width: 80px;height: 84px;margin-bottom: 18px;opacity: 0.6;" />
						</view>
						<view>
							<text style="color: #797171;"> 暂无相关活动，请积极参加~</text>
						</view>
					</view>
				</block>
			</view>

		</view>
		<tn-popup mode="center" width="300px" height="500px" closeBtn="true" borderRadius="20px" v-model="modelShow">
			<view class="content">
				<scroll-view scroll-y="true" style="height: 480px;">
					<view>
						<view v-for="(item, index) in userData" :key="index"
							style="display: flex;align-items: center;clear: both;">
							<view class="image-pic tn-margin-sm"
								:style="'background-image:url(' + item.url + ');width: 60rpx;height: 60rpx;float: left;'">
								<view class="image-article"> </view>
							</view>
							<text>{{item.userName}}</text>
							<button class="min-btn" v-if="item.state == 1" disabled="disabled">已通过</button>
							<block v-else-if="item.state == 0">
								<button class="min-btn op" @click="opt(item.id, index, 1)">通过</button>
								<button class="min-btn op un" @click="opt(item.id, index, 2)">拒绝</button>
							</block>

							<button class="min-btn" v-else-if="item.state == 2" disabled="disabled">已拒绝</button>
						</view>
					</view>
				</scroll-view>

			</view>
		</tn-popup>
	</view>
</template>

<script>
	import template_page_mixin from '@/libs/mixin/template_page_mixin.js'
	import request from '@/common/request.js';
	export default {
		mixins: [template_page_mixin],
		data() {
			return {
				modelShow: false,
				list: [{
					tabName: '全部'
				}, {
					tabName: '待审核'
				}, {
					tabName: '已通过',
					//count: 5
				}, {
					tabName: '已拒绝'
				}],
				tabsIndex: 0,
				swiperIndex: 0,
				reserve: [],
				userData: [],
				statusTxt: ["待通过申请", "已通过申请", "已拒绝申请"]
			}
		},
		onLoad() {
			this.initData()
		},
		methods: {
			opt(id, index, status) {
				let _t = this
				request.post("friend/wx/activity/joinCheck", {
					state: status,
					id: id
				}).then(res => {
					let _data = res[1]['data']
					if (_data.code == 20000) {
						uni.showToast({
							title: '操作成功',
							icon: 'success',
							complete() {
								_t.userData[index].state = status
							}
						})
					}
				})
			},
			showDetail(id) {
				this.userData = [];
				this.loading = true

				let _t = this;
				request.get("friend/wx/activity/selectActivityDetail/" + id).then(res => {
					let _data = res[1]['data']
					if (_data.code == 20000) {
						this.userData = _data.data
					}

					this.loading = false
					this.modelShow = true
				})
			},
			deleteActivity(item, index) {
				let that = this;
				uni.showModal({
					title: '确认框',
					content: '确认删除本条活动吗?',
					success: function(res) {
						if (res.confirm) {
							// 确认删除
							console.log("删除编号为 " + item.id + " 的数据")
							//that.$delete(that.reserve, index)
							request.delete("friend/wx/activity/remove/" + item.id).then(res => {
								let _data = res[1]['data']
								if (_data.code == 20000) {
									console.log("删除成功")
									that.$delete(that.reserve, index)
								}else{
									console.log("删除失败")
								}
							})
						} else if (res.cancel) {
							console.log('用户点击取消');
						}
					}
				});
			},
			initData() {
				let _t = this;
				request.get("friend/wx/activity/selectMeReleaseActivity").then(res => {
					let _data = res[1]['data']
					if (_data.code == 20000) {
						let d = _data.data
						if (d && d.length > 0) {

							d.forEach(ccc => {
								ccc.stateTxt = this.statusTxt[ccc.state]
								let _img = ccc.image.split(",") || []
								ccc.url = _img[0] || "";
							})

							_t.reserve = d;
						}
					}
				})
			},
		}
	}
</script>

<style lang="scss" scoped>
	.tn-text-df {
		line-height: 26px;
		;
	}

	/* 胶囊*/
	.tn-custom-nav-bar__back {
		width: 100%;
		height: 100%;
		position: relative;
		display: flex;
		justify-content: space-evenly;
		align-items: center;
		box-sizing: border-box;
		background-color: rgba(0, 0, 0, 0.15);
		border-radius: 1000rpx;
		border: 1rpx solid rgba(255, 255, 255, 0.5);
		color: #FFFFFF;
		font-size: 18px;

		.icon {
			display: block;
			flex: 1;
			margin: auto;
			text-align: center;
		}

		&:before {
			content: " ";
			width: 1rpx;
			height: 110%;
			position: absolute;
			top: 22.5%;
			left: 0;
			right: 0;
			margin: auto;
			transform: scale(0.5);
			transform-origin: 0 0;
			pointer-events: none;
			box-sizing: border-box;
			opacity: 0.7;
			background-color: #FFFFFF;
		}
	}

	.order-wrap {
		display: flex;
		flex-direction: column;
		height: calc(100vh - var(--window-top));
		width: 100%;
	}

	.swiper {
		height: 100%;

		&__box {
			flex: 1;
		}

		&__item {
			height: 100%;
		}
	}

	.image-circle {
		// padding: 95rpx;
		width: 190rpx;
		height: 190rpx;
		font-size: 40rpx;
		font-weight: 300;
		position: relative;
	}

	.image-pic {
		background-size: cover;
		background-repeat: no-repeat;
		// background-attachment:fixed;
		background-position: top;
		border-radius: 10rpx;
		width: 190rpx;
		height: 190rpx;
	}

	.info-btn {
		font-size: 12px;
		font-weight: bold;
		color: #f9811a;
		border-radius: 10px;
	}

	.min-btn {
		height: 50rpx;
		width: 120rpx;
		padding: 0 8px;
		font-size: 12px;
		line-height: 26px;
		margin: 0 10px;
	}

	.min-btn.op {
		width: 90rpx;
		background: #8d8df1;
		color: #f5f5f5;
	}

	.min-btn.un {
		background-color: crimson;
		color: #000;
	}
</style>
